package com.ruoyi.web.controller.cs;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.ruoyi.common.core.controller.BasicsController;
import com.ruoyi.common.core.domain.Response;
import com.ruoyi.common.core.page.ResponsePageInfo;
import com.ruoyi.common.utils.poi.Excel2Util;
import com.ruoyi.cs.domain.vo.TUserSyVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cs.domain.TUserTg;
import com.ruoyi.cs.service.ITUserTgService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 用户推广信息记录Controller
 * 
 * @author ruoyi
 * @date 2021-03-25
 */
@Api(tags = "用户推广信息记录")
@RestController
@RequestMapping("/cs/usertg")
public class TUserTgController extends BasicsController
{
    @Autowired
    private ITUserTgService tUserTgService;

    /**
     * 查询用户推广信息记录列表
     */
    @ApiOperation("查询用户推广信息记录列表")
    @PreAuthorize("@ss.hasPermi('system:tg:listBack')")
    @GetMapping("/listBack")
    public ResponsePageInfo<TUserTg> listBack(TUserTg tUserTg)
    {
        startPage();
        List<TUserTg> list = tUserTgService.selectTUserTgList(tUserTg);
        return toResponsePageInfo(list);
    }

    /**
     * 导出用户推广信息记录列表
     */
    @ApiOperation("导出用户推广信息记录列表")
    @PreAuthorize("@ss.hasPermi('system:tg:export')")
    @Log(title = "用户推广信息记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public Response<String> export(TUserTg tUserTg)
    {
        List<TUserTg> list = tUserTgService.selectTUserTgList(tUserTg);
        Excel2Util<TUserTg> util = new Excel2Util<TUserTg>(TUserTg.class);
        return util.exportExcel(list, "tg");
    }

    /**
     * 获取用户推广信息记录详细信息
     */
    @ApiOperation("获取用户推广信息记录详细信息")
    @PreAuthorize("@ss.hasPermi('system:tg:query')")
    @GetMapping(value = "/{tgId}")
    public Response<TUserTg> getInfo(
            @ApiParam(name = "tgId", value = "用户推广信息记录ID", required = true)
            @PathVariable("tgId") String tgId)
    {
        return Response.success(tUserTgService.selectTUserTgById(tgId));
    }

    /**
     * 新增用户推广信息记录
     */
    @ApiOperation("新增用户推广信息记录")
    @PreAuthorize("@ss.hasPermi('system:tg:add')")
    @Log(title = "用户推广信息记录", businessType = BusinessType.INSERT)
    @PostMapping
    public Response<Integer> add(@RequestBody TUserTg tUserTg)
    {
        return toResponse(tUserTgService.insertTUserTg(tUserTg));
    }

    /**
     * 修改用户推广信息记录
     */
    @ApiOperation("修改用户推广信息记录")
    @PreAuthorize("@ss.hasPermi('system:tg:edit')")
    @Log(title = "用户推广信息记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public Response<Integer> edit(@RequestBody TUserTg tUserTg)
    {
        return toResponse(tUserTgService.updateTUserTg(tUserTg));
    }

    /**
     * 删除用户推广信息记录
     */
    @ApiOperation("删除用户推广信息记录")
    @PreAuthorize("@ss.hasPermi('system:tg:remove')")
    @Log(title = "用户推广信息记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tgIds}")
    public Response<Integer> remove(
            @ApiParam(name = "tgIds", value = "用户推广信息记录ID,多个用，隔开", required = true)
            @PathVariable String[] tgIds)
    {
        return toResponse(tUserTgService.deleteTUserTgByIds(tgIds));
    }

    /**--------------------------------------前端-------------------------------------------------*/
    /**
     * 查询用户推广信息记录列表
     */
    @ApiOperation("web查询用户推广信息记录列表")
    @RequestMapping(name="查询用户推广信息记录列表",value="list",method = RequestMethod.POST)
    public ResponsePageInfo<List<Map>> list(@RequestBody  TUserTg tUserTg)
    {
        startPage(tUserTg.getPageNum(),tUserTg.getPageSize());
        List<Map> list = tUserTgService.userTgListWeb(tUserTg);
        Map<String, Object> map = new HashMap<>();
        map.put("total",list.size());
        return getDataTableObj(map,list);
    }

}
